package display {
	import flare.vis.data.NodeSprite;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	
	import org.aswing.AsWingManager;
	import org.aswing.BoxLayout;
	import org.aswing.Container;
	import org.aswing.JFrame;
	import org.aswing.JList;
	import org.aswing.JScrollPane;

	public class SelectionSummarySprite extends Sprite {
		public var frame:JFrame;
		public var names:JList;
		public function SelectionSummarySprite(stage:Stage) {
			super();
			AsWingManager.setRoot(stage);
			frame = new JFrame(null, "Selection summary", false);
			frame.setClosable(false);
			frame.setDragable(false);
			frame.setResizable(false);
//			frame.setFocusable(false);
			var pane:Container = frame.getContentPane();
			pane.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
			
			
			names = new JList();
			var scroll:JScrollPane = new JScrollPane();
			scroll.setView(names);
			pane.append(scroll);
			frame.setX(1000);
			frame.setY(240);
			frame.setSizeWH(200, 150);
			frame.show();
		}
		public function update(items:Array, cause:MouseEvent):void {
			if (items.length <= 0) return;
			var list:Array = [];
			for each (var node:NodeSprite in items) {
				list.push(node.data.name);
			}
			trace(' >' + list.length);
			names.setListData(list);
			/*
			var stageX:Number = cause.stageX, stageY:Number = cause.stageY;
			var xOffset:Number = 0, yOffset:Number = 25;
			frame.x = stageX + xOffset;
			frame.y = stageY + yOffset;
			node = items[0];
			var b:Rectangle = new Rectangle(0, 0, node.stage.stageWidth, node.stage.stageHeight);
			var r:Rectangle = frame.getBounds(node.stage);
			if (r.width > b.width) {
				frame.x = b.left;
			} else if (r.left < b.left + 5) {
				frame.x = stageX + xOffset;
			} else if (r.right > b.right - 5) {
				frame.x = stageX - 2 - r.width;
			}
			if (r.height > b.height) {
				frame.y = b.top;
				trace(' > 1 ' + frame.y);
			} if (r.top < b.top + 5) {
				frame.y = stageY - yOffset;
				trace(' > 2 ' + frame.y);
			} else if (r.bottom > b.bottom - 5) {
				frame.y = Math.max(stageY - 7 - r.height, 0);
				//				trace(' > 3 ' + frame.y + ' ' + r.height);
			}
			frame.show();
			*/
		}
		public function hide():void {
			frame.hide();
		}
	}
}